//
//  MemberCell.m
//  兼职页面
//
//  Created by kuiyuan liang on 2021/5/23.
//

#import "MemberCell.h"
#import "CommonUtil.h"
#import "AccuracyView.h"

@interface MemberCell ()

@property (strong, nonatomic) UIView * whiteView;

@property (strong, nonatomic) UIImageView * iconImageView;
@property (strong, nonatomic) UILabel * nameLabel;
@property (strong, nonatomic) UILabel * timeLabel;
@property (strong, nonatomic) UILabel * statusLabel;
@property (strong, nonatomic) UILabel * typeLabel;
@property (strong, nonatomic) UILabel * resultLabel1;
@property (strong, nonatomic) UILabel * resultLabel2;
@property (strong, nonatomic) AccuracyView * accuracyView;

@property (strong, nonatomic) UIButton * btn1;
@property (strong, nonatomic) UIButton * btn2;
@property (strong, nonatomic) UIButton * btn3;

@property (strong, nonatomic) UIView * lineView1;
@property (strong, nonatomic) UIView * lineView2;
@property (strong, nonatomic) UIView * lineView3;


@property (strong, nonatomic) UILabel * readLabel;

@end

@implementation MemberCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = [UIColor clearColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.whiteView];
        [self.whiteView addSubview:self.iconImageView];
        [self.whiteView addSubview:self.typeLabel];
        [self.whiteView addSubview:self.nameLabel];
        [self.whiteView addSubview:self.timeLabel];
        [self.whiteView addSubview:self.resultLabel1];
        [self.whiteView addSubview:self.statusLabel];
        [self.whiteView addSubview:self.resultLabel2];
        [self.whiteView addSubview:self.accuracyView];
        [self.whiteView addSubview:self.btn1];
        [self.whiteView addSubview:self.deleateBtn];
        [self.whiteView addSubview:self.selectBtn];
        [self.whiteView addSubview:self.lineView1];
        [self.whiteView addSubview:self.lineView2];
        [self.whiteView addSubview:self.lineView3];
        [self.whiteView addSubview:self.readLabel];
    }
    return self;
}

-(void)layoutSubviews{
    [super layoutSubviews];
    [self countFrame];
}

- (void)countFrame{
    if (self.isGangcai) {
        self.whiteView.frame = CGRectMake(0, AD(5), self.width, AD(155));
        self.btn1.top = self.accuracyView.bottom + AD(5);
        self.btn2.top = self.btn1.top;
        self.btn3.top = self.btn1.top;
        
        self.lineView1.top = self.btn1.top;
        self.lineView2.top = self.btn1.top;
        self.lineView3.top = self.btn1.top;
    }else{
        self.whiteView.width = self.width - AD(20);
    }
    
    self.typeLabel.right = self.whiteView.width;
    self.accuracyView.width = self.whiteView.width;
    self.btn1.width = self.whiteView.width/3;
    self.deleateBtn.width = self.whiteView.width/3;
    self.selectBtn.width = self.whiteView.width/3;
    self.deleateBtn.left = self.btn1.right;
    self.selectBtn.left = self.deleateBtn.right;
    self.lineView1.width = self.whiteView.width;
    self.lineView2.left = self.deleateBtn.left;
    self.lineView3.left = self.selectBtn.left;
    self.timeLabel.bottom = self.nameLabel.bottom;
}

-(void)refreshWithData:(NSInteger)data{
    self.nameLabel.text = @"我的团长连长";
    self.timeLabel.text = @"2021-05-03 : 10:6:30";
    self.typeLabel.text = @"三肖";
    self.resultLabel1.text = @"战绩:4对1";
    self.statusLabel.text = @"锁定";
    self.resultLabel2.text = @"第034期:-鼠-虎-兔-";
    

    if (self.isGangcai) {

        [self.btn1 setTitle:@"618" forState:UIControlStateNormal];
        [self.btn1  setImage:[UIImage imageNamed:@"icon_zan_select"] forState:UIControlStateNormal];
        [self.btn1  setImage:[UIImage imageNamed:@"icon_zan_select"] forState:UIControlStateSelected];
        

        [self.btn2 setTitle:@"订阅" forState:UIControlStateNormal];
        [self.btn2 setImage:[UIImage imageNamed:@"subscribe_normal"] forState:UIControlStateNormal];
        [self.btn2 setImage:[UIImage imageNamed:@"subscribe_select"] forState:UIControlStateSelected];
        

        [self.btn3 setTitle:@"统计" forState:UIControlStateNormal];
        [self.btn3 setImage:[UIImage imageNamed:@"icon_edit"] forState:UIControlStateNormal];
        [self.btn3 setImage:[UIImage imageNamed:@"icon_edit"] forState:UIControlStateSelected];
        self.typeLabel.hidden = YES;
        self.readLabel.hidden = false;
        
        
        
    }else{

        self.readLabel.hidden = YES;
        [self.btn1  setTitle:@"订阅" forState:UIControlStateNormal];
        [self.btn1  setImage:[UIImage imageNamed:@"subscribe_normal"] forState:UIControlStateNormal];
        [self.btn1  setImage:[UIImage imageNamed:@"subscribe_select"] forState:UIControlStateSelected];
        
        // 删除按钮缺一张选中图
        [self.btn2 setTitle:@"删除" forState:UIControlStateNormal];
        [self.btn2 setImage:[UIImage imageNamed:@"icon_deleate"] forState:UIControlStateNormal];
        
        
        [self.btn3 setTitle:@"选中" forState:UIControlStateNormal];
        [self.btn3 setImage:[UIImage imageNamed:@"select_normal"] forState:UIControlStateNormal];
        [self.btn3 setImage:[UIImage imageNamed:@"select_select"] forState:UIControlStateSelected];
        
    }
    
    
    
    [self.nameLabel sizeToFit];
    [self.resultLabel1 sizeToFit];
    self.statusLabel.left = self.resultLabel1.right + AD(10);
    self.timeLabel.left = self.nameLabel.right + AD(2);
    

    
}

- (void)subscribeBtnClick:(UIButton *)sender{
    NSLog(@"%@",sender.titleLabel.text);
    sender.selected = !sender.selected;
}


#pragma mark - lazy
-(UIView *)whiteView{
    if (!_whiteView) {
        _whiteView = [[UIView alloc] initWithFrame:CGRectMake(AD(10), 0, AD(200), AD(150))];
        _whiteView.layer.cornerRadius = AD(10);
        _whiteView.clipsToBounds = YES;
        _whiteView.backgroundColor = [UIColor whiteColor];
    }
    return _whiteView;
}

-(UIImageView *)iconImageView{
    if (!_iconImageView) {
        _iconImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"statistics_default.jpg"]];
        _iconImageView.layer.cornerRadius = AD(35);
        _iconImageView.clipsToBounds = YES;
        _iconImageView.frame = CGRectMake(AD(5), self.typeLabel.bottom, AD(70), AD(70));
    }
    return _iconImageView;
}

-(UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(_iconImageView.right + AD(3), self.typeLabel.bottom, AD(200), AD(20))];
        _nameLabel.textColor = [UIColor blackColor];
        _nameLabel.font = [UIFont boldSystemFontOfSize:AD(16)];
    }
    return _nameLabel;
}
-(UILabel *)timeLabel{
    if (!_timeLabel) {
        _timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, AD(200), AD(15))];
        _timeLabel.textColor = [UIColor lightGrayColor];
        _timeLabel.font = [UIFont systemFontOfSize:AD(9)];
    }
    return _timeLabel;
}



-(UILabel *)resultLabel1{
    if (!_resultLabel1) {
        _resultLabel1 = [[UILabel alloc] initWithFrame:CGRectMake(_nameLabel.left, self.nameLabel.bottom, AD(200), AD(15))];
        _resultLabel1.textColor = [UIColor blackColor];
        _resultLabel1.font = [UIFont systemFontOfSize:AD(12)];
    }
    return _resultLabel1;
}

-(UILabel *)statusLabel{
    if (!_statusLabel) {
        _statusLabel = [[UILabel alloc] initWithFrame:CGRectMake(_nameLabel.right + AD(3), _nameLabel.bottom, AD(30), AD(15))];
        _statusLabel.textColor = [UIColor whiteColor];
        _statusLabel.font = [UIFont boldSystemFontOfSize:AD(11)];
        _statusLabel.backgroundColor = RGB(38.0, 133.0, 217.0);
        _statusLabel.layer.cornerRadius = AD(3);
        _statusLabel.clipsToBounds = YES;
        _statusLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _statusLabel;
}


-(UILabel *)resultLabel2{
    if (!_resultLabel2) {
        _resultLabel2 = [[UILabel alloc] initWithFrame:CGRectMake(_nameLabel.left, self.resultLabel1.bottom, AD(200), AD(20))];
        _resultLabel2.textColor = [UIColor blackColor];
        _resultLabel2.font = [UIFont boldSystemFontOfSize:AD(16)];
    }
    return _resultLabel2;
}


-(UILabel *)typeLabel{
    if (!_typeLabel) {
        _typeLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, AD(40), AD(20))];
        _typeLabel.textColor = [UIColor whiteColor];
        _typeLabel.font = [UIFont boldSystemFontOfSize:AD(12)];
        _typeLabel.textAlignment = NSTextAlignmentCenter;
        _typeLabel.layer.cornerRadius = AD(5);
        _typeLabel.clipsToBounds = YES;
        _typeLabel.backgroundColor = RGB(255.0, 89.0, 117.0);
    }
    return _typeLabel;
}

-(AccuracyView *)accuracyView{
    if (!_accuracyView) {
        _accuracyView = [[AccuracyView alloc] initWithFrame:CGRectMake(0, self.iconImageView.bottom, AD(200), AD(20))];
    }
    return _accuracyView;
}

-(UIButton *)btn1{
    if (!_btn1) {
        _btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
        
        [_btn1 setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
        [_btn1 setTitleColor:RGB(255.0, 89.0, 117.0) forState:UIControlStateSelected];
        _btn1.titleLabel.font = [UIFont systemFontOfSize:AD(12)];
        [_btn1 addTarget:self action:@selector(subscribeBtnClick:) forControlEvents:UIControlEventTouchUpInside];

        _btn1.frame = CGRectMake(0, _accuracyView.bottom, 0, AD(40));
        _btn1.imageEdgeInsets = UIEdgeInsetsMake(0, AD(-5), 0, 0);
    }
    return _btn1;
}

-(UIButton *)deleateBtn{
    if (!self.btn2) {
        _btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
        
        [self.btn2 setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
        [self.btn2 setTitleColor:RGB(255.0, 89.0, 117.0) forState:UIControlStateSelected];
        self.btn2.titleLabel.font = [UIFont systemFontOfSize:AD(12)];
        [self.btn2 addTarget:self action:@selector(subscribeBtnClick:) forControlEvents:UIControlEventTouchUpInside];

        self.btn2.frame = CGRectMake(0, _accuracyView.bottom, 0, AD(40));
        self.btn2.imageEdgeInsets = UIEdgeInsetsMake(0, AD(-5), 0, 0);
    }
    return self.btn2;
}


-(UIButton *)selectBtn{
    if (!self.btn3) {
        self.btn3 = [UIButton buttonWithType:UIButtonTypeCustom];
        
        [self.btn3 setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
        [self.btn3 setTitleColor:RGB(255.0, 89.0, 117.0) forState:UIControlStateSelected];
        self.btn3.titleLabel.font = [UIFont systemFontOfSize:AD(12)];
        [self.btn3 addTarget:self action:@selector(subscribeBtnClick:) forControlEvents:UIControlEventTouchUpInside];

        self.btn3.frame = CGRectMake(0, _accuracyView.bottom, 0, AD(40));
        self.btn3.imageEdgeInsets = UIEdgeInsetsMake(0, AD(-5), 0, 0);
    }
    return self.btn3;
}

-(UIView *)lineView1{
    if (!_lineView1) {
        _lineView1 = [[UIView alloc] initWithFrame:CGRectMake(0, _accuracyView.bottom, 0, AD(1))];
        _lineView1.backgroundColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.3];
    }
    return _lineView1;
}

-(UIView *)lineView2{
    if (!_lineView2) {
        _lineView2 = [[UIView alloc] initWithFrame:CGRectMake(0, _accuracyView.bottom, AD(1), AD(40))];
        _lineView2.backgroundColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.3];
    }
    return _lineView2;
}

-(UIView *)lineView3{
    if (!_lineView3) {
        _lineView3 = [[UIView alloc] initWithFrame:CGRectMake(0, _accuracyView.bottom, AD(1), AD(40))];
        _lineView3.backgroundColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.3];
    }
    return _lineView3;
}

-(UILabel *)readLabel{
    if (!_readLabel) {
        _readLabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-AD(40), 0, AD(60), AD(25))];
        _readLabel.textColor = [UIColor whiteColor];
        _readLabel.font = [UIFont boldSystemFontOfSize:AD(11)];
        _readLabel.backgroundColor = RGB(255, 76, 106);
        _readLabel.text = @"已读";
        _readLabel.textAlignment = NSTextAlignmentCenter;
        _readLabel.transform = CGAffineTransformMakeRotation(M_PI*0.25);
    }
    return _readLabel;
}


@end

